package com.haier.a920changjingyanshidemo.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.haier.a920changjingyanshidemo.R;

/**
 * Created by 01457215 on 2017/8/22.
 */

public class MyShouHouDialog extends Dialog {


    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public MyShouHouDialog(@NonNull final Context context) {
        super(context);

        View inflate = getLayoutInflater().inflate(R.layout.dialog_shouhou, null);

        inflate.findViewById(R.id.huanyan_shouhou).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "正在拨打电话", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:4006999999"));
                context.startActivity(intent);
            }
        });
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.setContentView(inflate);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams p = dialogWindow.getAttributes();
        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();
        getWindow().setAttributes(p);
        p.height = (int) (d.getHeight() * 0.35);
        p.width = (int) (d.getWidth() * 0.8);
        p.gravity = Gravity.CENTER;
        dialogWindow.setAttributes(p);
    }
}
